import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Arrays;
import java.util.Collections;

class LuhnValidator {

    boolean isValid(String candidate) {
        /// replace all spaces
        candidate = candidate.replaceAll("\\s?", "");

        if (candidate.length() < 2)
            return false;

        /// not digital
        if (!candidate.matches("[0-9]{1,}"))
            return false;

        String[] candidateSplits = candidate.split("");

        /// reverse string[]
        Collections.reverse(Arrays.asList(candidateSplits));

        int result = 0;
        for (int i = 0; i < candidateSplits.length; i++) {
            int t = Integer.valueOf(candidateSplits[i]);
            result += i % 2 == 1 ? t * 2 > 9 ? t * 2 - 9 : t * 2 : t;
        }

        return result % 10 == 0;
    }

}
